﻿Imports Npgsql
Imports System.Text

Public Class NewTicket
    Dim aTicket As New clsTicket

    Private Sub TicketDetail_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        PopulateTechDropDown()
        PopulatePriorityDropDown()
        PopulateIssuetypeDropDown()
        PopulateUsersDropDown()
    End Sub

    Private Sub PopulateTechDropDown()
        Me.cmbxAssignedTo.DisplayMember = "assignedto"
        Me.cmbxAssignedTo.ValueMember = "userid"
        Me.cmbxAssignedTo.DataSource = clsUIBase.AddTechs()
    End Sub
    Private Sub PopulateUsersDropDown()
        Me.cbUsers.DisplayMember = "assignedto"
        Me.cbUsers.ValueMember = "userid"
        Me.cbUsers.DataSource = clsUIBase.AddUsers()
    End Sub
    Private Sub PopulatePriorityDropDown()
        Me.cbPriority.DisplayMember = "prioritydesc"
        Me.cbPriority.ValueMember = "priorityid"
        Me.cbPriority.DataSource = clsUIBase.RetrievePriorities()
    End Sub
    Private Sub PopulateIssuetypeDropDown()
        Me.cbIssuetype.DisplayMember = "issuetypedesc"
        Me.cbIssuetype.ValueMember = "issuetypeid"
        Me.cbIssuetype.DataSource = clsUIBase.RetrieveIssueTypes()
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If txtTicketSubject.Text.Length > 0 And txtTicketSubjectDesc.Text.Length > 0 Then
            aTicket.InsertTicket(CInt(cmbxAssignedTo.SelectedValue.ToString), CInt(cbIssuetype.SelectedValue.ToString), CInt(cbPriority.SelectedValue.ToString), CInt(cbUsers.SelectedValue.ToString), txtTicketSubject.Text.ToString, txtTicketSubjectDesc.Text.ToString)
            Me.Close()
        Else
            MsgBox("Please fill in all data fields!", vbOKOnly)
        End If
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub
End Class